<?php

	/*
		Jax Calendar v1.34 - Copyright (c) 2002-2004, Andreas John aka Jack (tR)
		This program and it's moduls are Open Source in terms of General Public Licens (GPL) v2.0

		eventlist.inc.php 		(the list of events)
	*/	

	
	// fit if nescessary:
	define( "PATH_TO_SCRIPT", "../" );

	
	// Global variables (have to be fit)	
	require_once ( dirname(__FILE__) . "/". "main.inc.php" );

	if ( !empty( $_GET["do"] ) ) $do = $_GET["do"]; else { $do = "show_list"; }
	if (!empty( $_SERVER["PHP_SELF"] )) $PHP_SELF = $_SERVER["PHP_SELF"];

	
	/**
	* @return void
	* @desc   Shows all dates of the specified period
	*/
	function show_list()
	{
		global $calendar_list, $cal_month, $cal_day, $cal_year, $now_hour,$now_min, $now_sec, 
		$status_img_dir, $is_dst, $loc_lang, $ox_tail, $view_cal_select, $view_default, $view, $cal_next_month, $cal_next_year, $PHP_SELF, $base_url;

		echo <<< TABLEHEAD
		<br />
		
		<!-- EVENT LIST (START) -->
		<div class="event_list">	
		<div id="the_content">		
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr class="headings"> 
				<td class="col_status"><img src="{$base_url["jax_cal"]}/images/1x1.gif" height="1" width="30">&nbsp;</td>
				<td class="col_date">{$loc_lang["date"]}</td>
				<td class="col_event">{$loc_lang["event"]}</td>
			</tr>
TABLEHEAD;
		

		if ( $view_cal_select )
		{
			$d1s = $d7s = $d14s = $d30s = $m3s = $m6s = $m12s = "";
			switch ($view)
			{
				/*case "d1"  : 
				{
					$d1s = "selected";				
					$now_start = intval(gmmktime(0,0,0,$cal_month,$cal_day,$cal_year,$is_dst));
					$now_stop  = intval(gmmktime(23,59,59,$cal_month,$cal_day,$cal_year,$is_dst));
					$now_stamp = intval(gmmktime($now_hour,$now_min, $now_sec, $cal_month, $cal_day, $cal_year,$is_dst));				
					break;
				}
				case "d30" : 
				{
					$d30s = "selected";
					$last_day_in_month = gmdate( "d", gmmktime(0,0,0,$cal_next_month, 0, $cal_next_year ) );
					$now_start = intval(gmmktime(0,0,0,$cal_month,01,$cal_year ));
					$now_stop  = intval(gmmktime(23,59,59,$cal_month,$last_day_in_month,$cal_year ));
					$now_stamp = intval(gmmktime(0,0,0,$cal_month,$cal_day,$cal_year ));
					break;
				}
				case "m12" : 
				{
					$m12s = "selected";
					$now_start = intval(gmmktime(0,0,0,01,01,$cal_year,$is_dst));
					$now_stop  = intval(gmmktime(23,59,59,12,31,$cal_year,$is_dst));
					$now_stamp = intval(gmmktime(0,0,0,$cal_month,$cal_day,$cal_year,$is_dst));
					break;
				}*/
				case "d1"  : 
				{
					$d1s = "selected";				
					$view_start = intval(gmmktime(0,0,0,$cal_month,$cal_day,$cal_year,$is_dst));
					$view_stop  = intval(gmmktime(23,59,59,$cal_month,$cal_day,$cal_year,$is_dst));
					$view_stamp = intval(gmmktime($now_hour,$now_min, $now_sec, $cal_month, $cal_day, $cal_year,$is_dst));				
					break;
				}
				case "d30" : 
				{
					$d30s = "selected";
					$last_day_in_month = num_days( $cal_year, $cal_month );
					$view_start = intval(gmmktime(0,0,0,$cal_month,01,$cal_year,$is_dst));
					$view_stop  = intval(gmmktime(23,59,59,$cal_month,$last_day_in_month,$cal_year,$is_dst));
					$view_stamp = intval(gmmktime(0,0,0,$cal_month,$cal_day,$cal_year,$is_dst));
					break;
				}
				case "m12" : 
				{
					$m12s = "selected";
					$view_start = intval(gmmktime(0,0,0,01,01,$cal_year,$is_dst));
					$view_stop  = intval(gmmktime(23,59,59,12,31,$cal_year,$is_dst));
					$view_stamp = intval(gmmktime(0,0,0,$cal_month,$cal_day,$cal_year,$is_dst));
					break;
				} 
			}
		}		
				
		$num_dates = $calendar_list->entries();
			
		$red_data = array();
		$calendar_list->get_entry(0,$red_data);
		$no_entries = true;
		
		$outputs = "";
		$ii = 0; // used for line colouring!
		for ( $i=0;$i<$num_dates;$i++ )
		{
/*			if ( ($now_stamp >= intval( $red_data["reminder_start"]) && $now_stamp <= intval($red_data["reminder_end"]))
			|| ( intval( $red_data["reminder_start"]) >= $now_start && intval($red_data["reminder_end"] <= $now_stop )) )*/
			if ( 
				( ( $red_data["reminder_start"] >= $view_start ) && ( $red_data["reminder_end"] <= $view_stop ) ) ||
				( ( $red_data["reminder_start"] < $view_start )  && ( $red_data["reminder_end"] > $view_stop ) ) ||
				( ( $red_data["reminder_start"] >= $view_start ) && ( $red_data["reminder_end"] >= $view_stop ) && ( $red_data["reminder_start"] <= $view_stop ) ) ||
				( ( $red_data["reminder_start"] <= $view_start ) && ( $red_data["reminder_end"] <= $view_stop ) && ( $red_data["reminder_end"] >= $view_start )  )
			)			
			
			{
				$no_entries = false;

				$date_str = "";
				if ( $red_data["x24"] == "1" )
				{
					$d_start = gmdate("d.m.Y",$red_data["event_start"]);
					$d_end   = gmdate("d.m.Y",$red_data["event_end"]);
					
					if ($d_start != $d_end) 
					{
						$date_str .= $d_start . " -<br>" . $d_end;
					} else $date_str .= $d_start;
				}
				else
				{
					$date_str = gmdate("d.m.Y H:i",$red_data["event_start"]);
	
					if ($red_data["event_start"] != $red_data["event_end"]) 
					{
						$date_str .= " -<br>" . gmdate("d.m.Y H:i",$red_data["event_end"]);
					}				
				}
				
				if (eregi("image::",$red_data["status"])) 
					$status_txt = '<img src="'.$base_url["jax_cal"]."/".$status_img_dir."/".eregi_replace("image::","",$red_data["status"]).'">';
				else 
					$status_txt = $red_data["status"];
				
				$outputs = '	<tr class="line_color'.($ii % 2).'" valign="top">'."\n"
				.'		<td align="center" valign="top" class="status">'.$status_txt.'&nbsp;</td>'."\n"
				.'		<td class="date"><nobr>'.$date_str."</nobr></td>\n"
				.'		<td class="event"><a href="'.$PHP_SELF."?Y=$cal_year&m=$cal_month&d=$cal_day&do=show_event&key=".$red_data["event_key"]."&$ox_tail&evt_date=".urlencode($date_str).'&evt_title='.urlencode($red_data["event_title"]).'">'.$red_data["event_title"]."</a></td>\n	</tr>\n". $outputs;
				$ii++;
			}
			$calendar_list->get_next_entry( $red_data );	
		}
		
		echo $outputs;
		
		if ( $no_entries ) 
		{ 
			echo '<tr><td colspan="3" class="error_message">'.$loc_lang["no_entries"].'...</b></td></tr>'; 
		}
		
	echo "</table>\n</div></div>\n";
		
	if ( $view_cal_select )
	{
		$ds = "&Y=$cal_year&m=$cal_month&d=$cal_day";

		$view_select_html = <<<VIEWSELECT
		<script language="JavaScript">
			function go2link()
			{
				var thisform = document.cal_view
	
	 			location.href="$PHP_SELF?$ds&$ox_tail&view="+
	 			thisform.cal_view.options[thisform.cal_view.options.selectedIndex].value
			}
		</script>
		
		<form name="cal_view" method="post" action="" class="cal_view_select" align="right">
		{$loc_lang["calendar_view"]}:
		<select name="cal_view" onchange="javascript:go2link();">
		    <option value="d1" $d1s>{$loc_lang["view_day"]}</option>
		    <option value="d30" $d30s>{$loc_lang["view_month"]}</option>
		    <option value="m12" $m12s>{$loc_lang["view_1year"]}</option>
		  </select>
		</form>

VIEWSELECT;

	echo <<<FOOTER
		<table>
		<tr><td>$view_select_html</td>
		<td><script language="JavaScript" src="{$base_url["jax_cal"]}/modules/clean4print.js" type="text/javascript"></script>
		<p align="right">&nbsp;&nbsp;<a href="javascript: Clean4Print('the_content');"><img src="{$base_url["jax_cal"]}/images/printer.gif" border="0" alt="Drucken" title="{$loc_lang["prepare_printing"]} (Netscape6/IE6)" width="16" height="14"></a>&nbsp;<a href="javascript: Clean4Print('the_content');">{$loc_lang["prepare_printing"]}</a></p>
		</td>
		<td><p align="right">&nbsp;&nbsp;<a href="{$_SERVER["PHP_SELF"]}?do=search_dates&Y=$cal_year&m=$cal_month&d=$cal_day&$ox_tail"><img src="{$base_url["jax_cal"]}/images/magnglass.gif" border="0" alt="{$loc_lang["search_dates"]}" title="{$loc_lang["search_dates"]}" width="16" height="14"></a>&nbsp;<a href="{$_SERVER["PHP_SELF"]}?do=search_dates&Y=$cal_year&m=$cal_month&d=$cal_day&$ox_tail">{$loc_lang["search_dates"]}</a></p></td></tr>
		</table>
FOOTER;
	    }
	
	echo "<!-- EVENT LIST (END) -->";

	}	
	
	
	
	/**
	* @return void
	* @desc   Shows the data of the selected event
	*/
	function show_event()
	{
		global $event_list, $cal_month, $cal_day, $cal_year, 
		$is_dst, $loc_lang, $ox_tail, $view_cal_select, $base_url;

		if (!empty( $_GET["key"] ) ) $key = $_GET["key"]; else exit;
		if (!empty( $_GET["evt_date"]) ) $evt_date = $_GET["evt_date"];	else $evt_date = "";
		if (!empty( $_GET["evt_title"]) ) $evt_title = stripslashes( $_GET["evt_title"] );	else $evt_title = "";		  
				
		$red_data = array();
			
		$search_pattern = array();
		$search_pattern["event_key"] = $key;
			
		$pos = $event_list->find_entry( $search_pattern );
		$event_list->get_entry( $pos, $red_data );
		$ev_description = stripslashes( $red_data["event_description"] );
		
		echo <<< TAB
			<h3 class="event_list_title">{$loc_lang["dates_and_events"]}</h3>
			
			<!-- EVENT INFO (START) -->
			<div class="event_info">
			<table width="100%" border="0" cellspacing="0" cellpadding="0" id="the_content">
				<tr class="headings"> 
			          <td class="date">$evt_date</td>
			          <td class="title">$evt_title</td>
			        </tr>           
			        <tr> 
			          <td>&nbsp;</td>
			          <td>&nbsp;</td>
			        </tr>                 
				<tr>
				  <td class="description" colspan="2">$ev_description</td>
				</tr>
				<tr> 
			          <td>&nbsp;</td>
			          <td>&nbsp;</td>
			        </tr>
			 </table>
		     </div>
		
TAB;
$PHP_SELF = $_SERVER['PHP_SELF'];
	echo <<<FOOTER
<table>
<tr><td><p><a onClick="this.href='javascript:history.go(-1);'" href=\"$PHP_SELF?Y=$cal_year&m=$cal_month&d=$cal_day&$ox_tail\"><img src="{$base_url["jax_cal"]}/images/back.gif" border="0"></a>&nbsp;&nbsp;<a onClick="this.href='javascript:history.go(-1);'" href=\"$PHP_SELF?Y=$cal_year&m=$cal_month&d=$cal_day&$ox_tail\">{$loc_lang["back_to_index"]}</a></p></td>
<td><script language="JavaScript" src="{$base_url["jax_cal"]}/modules/clean4print.js" type="text/javascript"></script>
<p align="right">&nbsp;&nbsp;<a href="javascript: Clean4Print('the_content');"><img src="{$base_url["jax_cal"]}/images/printer.gif" border="0" alt="Drucken" title="{$loc_lang["prepare_printing"]} (Netscape6/IE6)" width="16" height="14"></a>&nbsp;<a href="javascript: Clean4Print('the_content');">{$loc_lang["prepare_printing"]}</a></p>
</td></tr></table>
FOOTER;

	echo "	<!-- EVENT INFO (STOP) -->";
	
	}

	
	/**
	* @return void
	* @desc   Shows event search form
	*/
	function search_dates()
	{
		global $ox_tail;
		echo <<<SUCHFELD
<form name="form1" method="post" action="{$_SERVER["PHP_SELF"]}?do=look_for&$ox_tail">
  <input type="text" name="suchbegriff">
  <input type="submit" name="search" value="Suchen">
</form>
SUCHFELD;
	}
	
	
	/**
	* @return void
	* @desc   Shows the data of the selected event
	*/
	function look_for_dates()
	{
		global $calendar_list, $cal_month, $cal_day, $cal_year, $now_hour,$now_min, $now_sec, 
		$status_img_dir, $is_dst, $loc_lang, $ox_tail, $view_cal_select, $view_default, $view, $cal_next_month, $cal_next_year, $PHP_SELF, $base_url;

		if (!empty($_POST["suchbegriff"])) $suchbegriff = $_POST["suchbegriff"]; else $suchbegriff="";
		
		echo <<< TABLEHEAD
		<h3 class="event_list_title">{$loc_lang["found_dates"]} ("$suchbegriff")</h3>
		
		<!-- EVENT LIST (START) -->
		<div class="event_list">	
		<div id="the_content">		
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr class="headings"> 
				<td class="col_status"><img src="{$base_url["jax_cal"]}/images/1x1.gif" height="1" width="30">&nbsp;</td>
				<td class="col_date">{$loc_lang["date"]}</td>
				<td class="col_event">{$loc_lang["event"]}</td>
			</tr>
TABLEHEAD;
		

				
		$num_dates = $calendar_list->entries();
			
		$red_data = array();
		$calendar_list->get_entry(0,$red_data);
		$no_entries = true;
		
		$outputs = "";
		$ii = 0; // used for line colouring!
		for ( $i=0;$i<$num_dates;$i++ )
		{

			if ( !empty( $suchbegriff) && eregi( $suchbegriff, $red_data["event_title"] ) )
			{
				$no_entries = false;

				$date_str = "";
				if ( $red_data["x24"] == "1" )
				{
					$d_start = gmdate("d.m.Y",$red_data["event_start"]);
					$d_end   = gmdate("d.m.Y",$red_data["event_end"]);
					
					if ($d_start != $d_end) 
					{
						$date_str .= $d_start . " -<br>" . $d_end;
					} else $date_str .= $d_start;
				}
				else
				{
					$date_str = gmdate("d.m.Y H:i",$red_data["event_start"]);
	
					if ($red_data["event_start"] != $red_data["event_end"]) 
					{
						$date_str .= " -<br>" . gmdate("d.m.Y H:i",$red_data["event_end"]);
					}				
				}
				
				if (eregi("image::",$red_data["status"])) 
					$status_txt = '<img src="'.$base_url["jax_cal"]."/".$status_img_dir."/".eregi_replace("image::","",$red_data["status"]).'">';
				else 
					$status_txt = $red_data["status"];
				
				$outputs = '	<tr class="line_color'.($ii % 2).'" valign="top">'."\n"
				.'		<td align="center" valign="top" class="status">'.$status_txt.'&nbsp;</td>'."\n"
				.'		<td class="date"><nobr>'.$date_str."</nobr></td>\n"
				.'		<td class="event"><a href="'.$PHP_SELF."?Y=$cal_year&m=$cal_month&d=$cal_day&do=show_event&key=".$red_data["event_key"]."&$ox_tail&evt_date=".urlencode($date_str).'&evt_title='.urlencode($red_data["event_title"]).'">'.$red_data["event_title"]."</a></td>\n	</tr>\n". $outputs;
				$ii++;
			}
			$calendar_list->get_next_entry( $red_data );	
		}
		
		echo $outputs;
		
		if ( $no_entries ) 
		{ 
			echo '<tr><td colspan="3" class="error_message">'.$loc_lang["err_no_dates_found"]." (\"$suchbegriff\")".'...</b></td></tr>'; 
		}
		
	echo "</table>\n</div></div>\n";
		
	if ( $view_cal_select )
	{
		$ds = "&Y=$cal_year&m=$cal_month&d=$cal_day";

		$view_select_html = <<<VIEWSELECT
		<script language="JavaScript">
			function go2link()
			{
				var thisform = document.cal_view
	
	 			location.href="$PHP_SELF?$ds&$ox_tail&view="+
	 			thisform.cal_view.options[thisform.cal_view.options.selectedIndex].value
			}
		</script>
		
		<form name="cal_view" method="post" action="" class="cal_view_select" align="right">
		{$loc_lang["calendar_view"]}:
		<select name="cal_view" onchange="javascript:go2link();">
		    <option value="d1" $d1s>{$loc_lang["view_day"]}</option>
		    <option value="d30" $d30s>{$loc_lang["view_month"]}</option>
		    <option value="m12" $m12s>{$loc_lang["view_1year"]}</option>
		  </select>
		</form>

VIEWSELECT;

	echo <<<FOOTER
<table>
<tr><td>$view_select_html</td>
<td><script language="JavaScript" src="{$base_url["jax_cal"]}/modules/clean4print.js" type="text/javascript"></script>
<p align="right">&nbsp;&nbsp;<a href="javascript: Clean4Print('the_content');"><img src="{$base_url["jax_cal"]}/images/printer.gif" border="0" alt="Drucken" title="{$loc_lang["prepare_printing"]} (Netscape6/IE6)" width="16" height="14"></a>&nbsp;<a href="javascript: Clean4Print('the_content');">{$loc_lang["prepare_printing"]}</a></p>
</td>
<td><p align="right">&nbsp;&nbsp;<a href="{$_SERVER["PHP_SELF"]}?do=search_dates&Y=$cal_year&m=$cal_month&d=$cal_day&$ox_tail"><img src="{$base_url["jax_cal"]}/images/magnglass.gif" border="0" alt="{$loc_lang["search_dates"]}" title="{$loc_lang["search_dates"]}" width="16" height="14"></a>&nbsp;<a href="{$_SERVER["PHP_SELF"]}?do=search_dates&Y=$cal_year&m=$cal_month&d=$cal_day&$ox_tail">{$loc_lang["search_dates"]}</a></p></td></tr></table>
FOOTER;
	    }
	
	echo "<!-- EVENT LIST (END) -->";

	}
		

	switch ( trim($do) )	
	{
		case "show_event" : show_event();
			break;
		case "show_list"  : show_list();
			break;
		case "search_dates" : search_dates();
			break;	
		case "look_for"     : look_for_dates();
			break;	
	}	
	
?>

<!-- Please don't remove the link to the author's website!!! -->
<p class="author_info">Jax Calendar v1.34, by Jack (tR), <a href="http://www.jtr.de/scripting/php">www.jtr.de/scripting/php</a></p>